#include "Frm11.h"

Frm11::Frm11(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm11::~Frm11() {
}

void Frm11::onInit() {

}

void Frm11::createParts() {
	setMainArg(0, 0, 1024, 600);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- Panel : wMPanel1                     -----------------------------*/
	wMPanel1 = new STTPanel(p_rt, this, "wMPanel1");
	wMPanel1->setMainArg(353, 272, 457, 295, 0);
	wMPanel1->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 255, 1, 0xc0c0c0);

	/*----------------------------- Button : wMButton21                  -----------------------------*/
	wMButton21 = new STTButton(p_rt, wMPanel1, "wMButton21", 0);
	wMButton21->setMainArg(302, 51, 98, 48, false);
	wMButton21->setPressedArg("click me!", 0x0, "文泉驿微米黑", 16, 0);
	wMButton21->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton21->setReleasedArg("click me!", 0x0, "文泉驿微米黑", 16, 0);
	wMButton21->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton21->onEventHandler(Event::CLICKED, this, (EHandler) &Frm11::wMButton21_clk_cb);

	/*----------------------------- Switch : wMSwitch2                   -----------------------------*/
	wMSwitch2 = new STTSwitch(p_rt, wMPanel1, "wMSwitch2");
	wMSwitch2->setMainArg(127, 68, 80, 36, false, false);
	wMSwitch2->setMainStyle(9999, 0x808080, 0xffffff, 0, 0, 0xc0c0c0, 0, 0x0);
	wMSwitch2->setIndicStyle(9999, 0x1a2b1, 0xffffff, 0, 0, 0x0, 0, 0xffffff);
	wMSwitch2->setKnobStyle(9999, 0x1a2b1, 0xffffff, 0, 0, 0x0, 0, 0xffffff);

	/*----------------------------- Label : wMLabel13                    -----------------------------*/
	wMLabel13 = new STTLabel(p_rt, wMPanel1, "wMLabel13");
	wMLabel13->setMainArg(256, 142, 74, 31, "标签", TextAlign::LEFT, LabelLongMode::CLIP, 30);
	wMLabel13->setFonts(0x0, 16, "文泉驿微米黑", 0);
	wMLabel13->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel13->setFormatText(TextAlign::LEFT, LabelLongMode::CLIP, 30);

	/*----------------------------- Text : wMText2                       -----------------------------*/
	wMText2 = new STTTextArea(p_rt, wMPanel1, "wMText2");
	wMText2->setMainArg(143, 148, 57, 44, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMText2->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 11, 0, 4, 4, 255);
	wMText2->setPlaceholderText("")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::UC);
	wMText2->setFont(0x0, 16, "文泉驿微米黑", 0);

	/*----------------------------- Roller : wMRoller1                   -----------------------------*/
	wMRoller1 = new STTRoller(p_rt, wMPanel1, "wMRoller1");
	wMRoller1->setMainArg(360, 142, 75, 108, 0, "选项1\n选项2\n选项3", 0, false);
	wMRoller1->setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 1, 0xc0c0c0, 0, 0x0);
	wMRoller1->setSelectedStyle(0, 0x1a2b1, 0xffffff, 0, 255);
	wMRoller1->setFontStyle(0x0, 16, "文泉驿微米黑", 0xffffff, 16, "文泉驿微米黑", 0, 0);

	/*----------------------------- Arc : wMArc1                         -----------------------------*/
	wMArc1 = new STTArc(p_rt, wMPanel1, "wMArc1");
	wMArc1->setMainArg(28, 59, 99, 99, 50, 0, 100, 135, 405);
	wMArc1->setMainStyle(9999, 0xffffff, 0xffffff, 0, 0, 0, 0xffffff, 30, 0xa0a0a0, true, "");
	wMArc1->setIndicStyle(0x1a2b1, true, 30, "");
	wMArc1->setKnobStyle(false, 0, 0xffffff, 0xffffff, 0, 0x1a2b1, 0, 9999, "");

	/*----------------------------- Bar : wMBar1                         -----------------------------*/
	wMBar1 = new STTBar(p_rt, wMPanel1, "wMBar1");
	wMBar1->setMainArg(48, 225, 130, 43, 50, 0, 100);
	wMBar1->setMainStyle(9999, 0xa0a0a0, 0xffffff, GradDir::NONE, 0, 0xa0a0a0, 0, 0x0);
	wMBar1->setIndicStyle(9999, 0x1a2b1, 0xffffff, 0, 0, 0x1a2b1);

	/*----------------------------- MButton : wMMButton1                 -----------------------------*/
	wMMButton1 = new STTButton(p_rt, this, "wMMButton1", 1);
	wMMButton1->setMainArg(0, 0, 100, 50, false);
	wMMButton1->setImg("1", "./images/arrow_34_100X50.gray.svg", "");
	wMMButton1->setImg("0", "./images/arrow_34_100X50.svg", "");
	wMMButton1->bindOpenFormHandler(Event::CLICKED, "Frm01", PageMode::NEWWIN, NULL);

	/*----------------------------- Slider : wMSlider10                  -----------------------------*/
	wMSlider10 = new STTSlider(p_rt, this, "wMSlider10");
	wMSlider10->setMainArg(435, 17, 9, 167, 0, 0, 100, false);
	wMSlider10->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider10->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider10->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider10->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm11::wMSlider10_vch_cb);

	/*----------------------------- Label : wMLabel6                     -----------------------------*/
	wMLabel6 = new STTLabel(p_rt, this, "wMLabel6");
	wMLabel6->setMainArg(604, 220, 74, 32, "上", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel6->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel6->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel6->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Slider : wMSlider11                  -----------------------------*/
	wMSlider11 = new STTSlider(p_rt, this, "wMSlider11");
	wMSlider11->setMainArg(635, 17, 9, 167, 0, 0, 100, false);
	wMSlider11->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider11->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider11->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider11->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm11::wMSlider11_vch_cb);

	/*----------------------------- Slider : wMSlider12                  -----------------------------*/
	wMSlider12 = new STTSlider(p_rt, this, "wMSlider12");
	wMSlider12->setMainArg(708, 17, 9, 167, 0, 0, 100, false);
	wMSlider12->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider12->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider12->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider12->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm11::wMSlider12_vch_cb);

	/*----------------------------- Label : wMLabel7                     -----------------------------*/
	wMLabel7 = new STTLabel(p_rt, this, "wMLabel7");
	wMLabel7->setMainArg(402, 220, 74, 32, "左", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel7->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel7->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel7->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Label : wMLabel8                     -----------------------------*/
	wMLabel8 = new STTLabel(p_rt, this, "wMLabel8");
	wMLabel8->setMainArg(475, 220, 74, 32, "右", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel8->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel8->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel8->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Slider : wMSlider13                  -----------------------------*/
	wMSlider13 = new STTSlider(p_rt, this, "wMSlider13");
	wMSlider13->setMainArg(807, 17, 9, 167, 0, 0, 100, false);
	wMSlider13->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider13->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider13->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider13->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm11::wMSlider13_vch_cb);

	/*----------------------------- Label : wMLabel9                     -----------------------------*/
	wMLabel9 = new STTLabel(p_rt, this, "wMLabel9");
	wMLabel9->setMainArg(775, 220, 74, 16, "行", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel9->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel9->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel9->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Label : wMLabel10                    -----------------------------*/
	wMLabel10 = new STTLabel(p_rt, this, "wMLabel10");
	wMLabel10->setMainArg(0, 49, 227, 508, "间隙演示", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel10->setFonts(0xff0000, 28, "文泉驿微米黑", 0);
	wMLabel10->setMainStyle(0, 0x80ffff, 0xffffff, GradDir::NONE, 0, 0x0, 140);
	wMLabel10->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*----------------------------- Slider : wMSlider14                  -----------------------------*/
	wMSlider14 = new STTSlider(p_rt, this, "wMSlider14");
	wMSlider14->setMainArg(507, 17, 9, 167, 0, 0, 100, false);
	wMSlider14->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider14->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider14->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider14->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm11::wMSlider14_vch_cb);

	/*----------------------------- Label : wMLabel11                    -----------------------------*/
	wMLabel11 = new STTLabel(p_rt, this, "wMLabel11");
	wMLabel11->setMainArg(676, 220, 74, 32, "下", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel11->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel11->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel11->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Slider : wMSlider15                  -----------------------------*/
	wMSlider15 = new STTSlider(p_rt, this, "wMSlider15");
	wMSlider15->setMainArg(880, 17, 9, 167, 0, 0, 100, false);
	wMSlider15->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider15->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider15->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider15->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm11::wMSlider15_vch_cb);

	/*----------------------------- Label : wMLabel12                    -----------------------------*/
	wMLabel12 = new STTLabel(p_rt, this, "wMLabel12");
	wMLabel12->setMainArg(848, 220, 74, 16, "列", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel12->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel12->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel12->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*called after widget created.*/

	return; //createParts END
}

static STTWidget* pp = NULL;

void loadbg(Frm11* frm) {
	pp = frm->wMPanel1;
	STTStylePad *p = pp->getStyle()->p_pad;

	int left = p->getLeft();
	int right = p->getRight();
	int top = p->getTop();
	int bottom = p->getBottom();
	int row = p->getRow();
	int column = p->getColumn();

	frm->wMSlider10->setValue(left, true);
	frm->wMSlider14->setValue(right, true);
	frm->wMSlider11->setValue(top, true);
	frm->wMSlider12->setValue(bottom, true);
	frm->wMSlider13->setValue(row, true);
	frm->wMSlider15->setValue(column, true);
}

void Frm11::onLoad() {

	pp = wMPanel1;
	pp->setLayout(STTLayout::FlexLayout());
	STTLayout::setFlexFlow(pp, 4);//0单行模式，1单列模式，4多行模式，8反向单行模式,12反向多行模式，5多列模式,9反向单列模式，13反向多列模式

	AsynWorker *worker = new AsynWorker(getRuntime()->getAppInstance(this_thread::get_id()));
	//如需传入局部变量，可在网上搜索lambda表达式的用法
	worker->invoke([this]() {
		std::this_thread::sleep_for(std::chrono::milliseconds(200));//延时200ms
	})->onFinished([this]() {
		loadbg(this);//加载完成时，为确保控件属性已刷新，延时读取控件属性
	})->start();

}

bool Frm11::onClosing() {
	return true;
}

void Frm11::onDispose() {

}

void Frm11::onMyEvent(uint16_t code, LvEvent e) {
	cout<<"onMyEvent"<<endl;
}

static int itmp = 0;

void Frm11::wMButton21_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton21（click me!）的点击事件*/
	cout << "click me!" << endl;
}

void updatebg(Frm11* frm) {
	pp = frm->wMPanel1;
	STTStylePad *p = pp->getStyle()->p_pad;

	int left = frm->wMSlider10->getValue();
	p->setLeft(left);
	int right = frm->wMSlider14->getValue();
	p->setRight(right);
	int top = frm->wMSlider11->getValue();
	p->setTop(top);
	int bottom = frm->wMSlider12->getValue();
	p->setBottom(bottom);
	int row = frm->wMSlider13->getValue();
	p->setRow(row);
	int column = frm->wMSlider15->getValue();
	p->setColumn(column);
}

void Frm11::wMSlider10_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm11::wMSlider11_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm11::wMSlider12_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm11::wMSlider13_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm11::wMSlider14_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm11::wMSlider15_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}
